package com.yystar.support.util;

import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

import com.yystar.support.base.util.AppUtility;

/**
 * 
 * @author liuzhifei
 *
 */
public class SystemProperties {
    
    private Properties _properties;
    
    private static SystemProperties _instance = new SystemProperties();
    
    public static String get(String key) {

        return (String)_instance._properties.get(key);
    }

    public static void set(String key, String value) {

        _instance._properties.put(key, value);
    }
    
    public static SystemProperties getInstance(){
        return _instance;
    }
    
    private SystemProperties() {
        
        _properties = new Properties();

        Thread currentThread = Thread.currentThread();

        ClassLoader classLoader = currentThread.getContextClassLoader();

        try {
            URL url = classLoader.getResource("system.properties");

            if (url != null) {
                InputStream inputStream = url.openStream();

                _properties.load(inputStream);

                inputStream.close();
            }
        }
        catch (Exception e) {
        	AppUtility.recordException(e);
        }
    }
}
